package com.pudu.mydemo.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.pudu.pdrobot.App;
import com.pudutech.pdrobot.R;


/**
 * Created by rahul on 28/7/16.
 */
public class TastyToast {
    public static final int LENGTH_SHORT = 0;
    public static final int LENGTH_LONG = 1;


    public static final int SUCCESS = 1;
    public static final int WARNING = 2;
    public static final int ERROR = 3;
    public static final int INFO = 4;
    public static final int DEFAULT = 5;
    private static Toast mToast;
    private static Handler mHandler = new Handler();
    private static Runnable r = new Runnable() {
        @Override
        public void run() {
            mToast.cancel();
        }
    };

    static ErrorToastView errorToastView;


    public static void makeText(Context context, String msg, int length, int height) {
        mHandler.removeCallbacks(r);
        if(mToast == null) {
            mToast = new Toast(context);
        }
        View layout = LayoutInflater.from(context).inflate(R.layout.error_toast_layout, null, false);

        TextView text = (TextView) layout.findViewById(R.id.toastMessage);
        text.setText(msg);
        errorToastView = (ErrorToastView) layout.findViewById(R.id.errorView);
        errorToastView.startAnim();
        text.setBackgroundResource(R.drawable.error_toast);
        text.setTextColor(Color.parseColor("#FFFFFF"));
        mToast.setView(layout);
        mToast.setDuration(length);
        mToast.setGravity(Gravity.TOP, 0, height);
        mToast.show();
    }


}
